package com.zw.hrm.config;

import com.zw.hrm.constants.MQConstants;
import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class MQ_Config {
    @Value("${site.routingkey}")
    private String routingKey;

    @Bean(MQConstants.NAME_EXCHANGE_PAGE_DIRECT)
    public Exchange exchange(){
        return ExchangeBuilder.directExchange(MQConstants.NAME_EXCHANGE_PAGE_DIRECT).durable(true).build();
    }

    @Bean(MQConstants.NAME_QUEUE_PAGE_DIRECT)
    public Queue queue(){
        return new Queue(MQConstants.NAME_QUEUE_PAGE_DIRECT, true);
    }

    @Bean
    public Binding bindingQueueInformEmail(){
        return BindingBuilder.bind(queue()).to(exchange()).with(routingKey).noargs();
    }
}
